<script setup>
import { ref, reactive,computed } from "vue";
import dayjs from 'dayjs'
const step = ref(0);
const modalVisible = ref(false);
const formRef = ref();
const format = 'HH:mm'; 

const data = reactive({
  name: "",
  country: "",
  gender: "male",
  duration: "",
  typeApp: "",
  email: "",
});
const nextPage = (value) => {
  if (step.value == 1) {
    onSubmit();
    return;
  }
  step.value = value;
};

const selectButton = (buttonName) => {
  if (data.gender === buttonName) {
    data.gender = null;
  } else {
    data.gender = buttonName;
  }
};
const options = [
  {
    value: "jack",
    label: "Jack",
  },
  {
    value: "lucy",
    label: "Lucy",
  },
];

const handleCancel = () => {
  modalVisible.value = false;
};
const rules = {
  name: [
    { required: true, message: "Please input your name", trigger: "change" },
  ],
  country: [
    {
      required: true,
      message: "Please select your country",
      trigger: "change",
    },
  ],
  duration: [
    {
      required: true,
      message: "Please input your duration",
      trigger: "change",
    },
  ],
  typeApp: [
    { required: true, message: "Please input your typeApp", trigger: "change" },
  ],
  email: [
    { required: true, message: "Please input your email", trigger: "change" },
  ],
};
const onSubmit = () => {
  formRef.value
    .validate()
    .then(() => {
      const durationTemp = dayjs(data.duration.$d).format('HH:mm');
      fetch('https://example.com/api/endpoint', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({...data,duration:durationTemp})
    }).then(response=>{
      if (!response.ok) {
        throw new Error('Network response was not ok');
      }
      return response.json(); // 解析 JSON 格式的响应数据
    }).then(data=>{
      // 处理接口响应
      console.log('API Response:', data);
      step.value = value;
    }).catch(error => {
      // 处理接口调用错误
      console.error('API Error:', error);
    });
      
    })
    .catch((error) => {
      console.log("error", error);
    });
};

</script>
<!-- ./assets/logo.svg -->

<template>
  <div class="container">
    <header>
      <img alt="Vue logo" class="logo" src="./assets/title.png" height="50" />
    </header>

    <main v-if="step == 0">
      <div class="title">
        Turn your chat skills into <span class="hundred">$100</span> a day!
      </div>

      <div class="subtitle">We need you!!</div>
      <div class="need">
        <div class="row">
          <img src="./assets/en.png" height="20" class="icon" />
          <span class="text">Fluent in English communication.</span>
        </div>
        <div class="row">
          <img src="./assets/video.png" height="20" class="icon" />
          <span class="text">No video required.</span>
        </div>
        <div class="row">
          <img src="./assets/voice.png" height="20" class="icon" />
          <span class="text">No voice messages needed.</span>
        </div>
        <div class="row">
          <img src="./assets/personal.png" height="20" class="icon" />
          <span class="text">No personal information required.</span>
        </div>
        <div class="row">
          <img src="./assets/chats.png" height="20" class="icon" />
          <span class="text">All chats are private.</span>
        </div>
        <div class="row">
          <img src="./assets/unlock.png" height="20" class="icon" />
          <span class="text"
            >Act as our assigned character. Share private photos and videos with
            users to engage them and build relationships. Earn commission for
            each unlock.</span
          >
        </div>
        <div class="row">
          <img src="./assets/method.png" height="20" class="icon" />
          <span class="text"
            >Weekly salary settlements, via bank transfer or other
            methods.</span
          >
        </div>
      </div>

      <div class="subtitle">Job Description</div>
      <div class="desc">
        We'll provide a simple test to determine your starting level. Based on
        this, you'll be assigned different numbers of roles. The more roles you
        have, the more customers you'll attract, leading to higher revenue.<br />
        We'll give you a chat app that won't collect any of your information,
        ensuring privacy and security.<br />
        Your task is to use your communication skills to attract customers and
        encourage them to pay for private photos and videos of these roles.
      </div>

      <div class="subtitle">Your commission settlement</div>
      <div class="desc">
        We aim to help you boost your earnings further. Your income has no
        limits, depending on your hard work and improving skills. The more
        people you attract, the more you earn. You can track your income in
        real-time and receive weekly deposits to your bank account or another
        preferred method. Many users are already earning $100 daily.
      </div>

      <div class="subtitle">Long-term growth opportunities</div>
      <div class="desc">
        If you are exceptional, we can provide you with a career advancement
        path where you could become a team leader or a regional manager,
        accompanied by a corresponding increase in income. We currently have
        companies established in some countries. If you are interested and we
        happen to have an office nearby, we are willing to offer you a full-time
        offline job.
      </div>


      <!-- <div class="button" @click="nextPage(1)">
        I WANT TO GET PAID TO FLIRT ONLINE
      </div> -->
    </main>
    
    <main v-if="step == 1">
      <a-form ref="formRef" :model="data" :rules="rules" layout="vertical">
        <div class="subtitle" style="margin-top: 10px;">Enter your name</div>
        <a-form-item ref="name" name="name">
          <a-input v-model:value="data.name" />
        </a-form-item>

        <div class="subtitle">Select your country</div>
        <a-form-item ref="country" name="country">
          <a-select v-model:value="data.country" :options="options">
            <!-- <a-select-option value="shanghai">Zone one</a-select-option>
            <a-select-option value="beijing">Zone two</a-select-option> -->
          </a-select>
        </a-form-item>

        <div class="subtitle">Select your gender</div>
        <div class="gender-container">
          <a-button
            type="default"
            :class="{ active: data.gender === 'male' }"
            style="width: 150px"
            @click="selectButton('male')"
            >Male</a-button
          >
          <a-button
            type="default"
            :class="{ active: data.gender === 'female' }"
            style="width: 150px"
            @click="selectButton('female')"
            >Female</a-button
          >
          <a-button
            type="default"
            :class="{ active: data.gender === 'other' }"
            style="width: 150px"
            @click="selectButton('other')"
            >Other</a-button
          >
        </div>

        <div class="subtitle">
          How many hours a week do you have available to flirt online?
        </div>
        <a-form-item name="duration">
          <a-time-picker
            v-model:value="data.duration"
            placeholder="-- : --"
            style="width: 200px"
            :showNow="false"
            :format="format"
          />
        </a-form-item>

        <div class="subtitle">Type your whatsapp / telegram</div>
        <a-form-item ref="typeApp" name="typeApp">
          <a-input v-model:value="data.typeApp" />
        </a-form-item>

        <div class="subtitle">Enter your email</div>
        <a-form-item ref="email" name="email">
          <a-input v-model:value="data.email" />
        </a-form-item>
      </a-form>

      <div class="button" @click="nextPage(2)">SEND</div>

      <a-modal :open="modalVisible" @cancel="handleCancel" :footer="null">
        <div class="succ-desc">Please fill in all the information!</div>
      </a-modal>
    </main>

    <main v-if="step == 2" class="succ">
      <div class="subtitle" style="margin: 20px 0 25px 0">
        Data Submitted Successfully!
      </div>
      <div class="succ-desc">
        A staff member will be in contact with you shortly.
      </div>
    </main>

    <div class="contact">
        <a class="contact-item" href="https://bit.ly/4dk4FH8" target="_blank">
            <img src="./assets/whatsapp.png" width="20" alt="WhatsApp"/>
            <span class="contact-text">Whatsapp</span>
        </a>
        <a class="contact-item" href="https://bit.ly/3U9i6SA" target="_blank">
          <img src="./assets/tele.png" width="20"/>
          <span class="contact-text">Telegram</span>
        </a>
      </div>
  </div>
</template>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  background: url("./assets/bg.png") no-repeat;
  background-size: cover;
  background-attachment: fixed;
  width: 100vw;
  height: 100vh;
  justify-content: center;
}
header {
  position: fixed;
  top: 40px;
}

.contact{
  position: absolute;
  bottom: 100px;
  right: calc((100vw - 1200px) / 2); 
  width: 190px; 
  display: flex;
  flex-direction: column;
  
}
.contact-item{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 8px;
  margin-bottom: 10px;
  padding: 10px 0;
}
.contact-text{
  margin-left: 10px;
  color: #000;
font-family: Helvetica;
font-style: normal;
font-weight: 400;
line-height: normal;
}
main {
  width: 680px;
  overflow-y: auto;
  margin: 130px 0 20px 0;
  background: #fff;
  padding: 40px 60px;
  border-radius: 10px;
}

.title {
  color: #4699ff;
  text-align: center;
  font-family: Helvetica;
  font-size: 38px;
  font-style: normal;
  font-weight: 700;
  line-height: normal;
  /* padding: 0 4px; */
}
.hundred {
  color: #ae46ff;
  font-family: Helvetica;
  font-size: 60px;
  font-style: normal;
  font-weight: 700;
  line-height: normal;
}
.subtitle {
  color: #4699ff;
  font-family: Helvetica;
  font-size: 25px;
  font-style: normal;
  font-weight: 700;
  line-height: normal;
  margin: 30px 0 20px 0;
}
.row {
  display: flex;
  margin-bottom: 15px;
}
.icon {
  margin: 1px 10px 0 0;
}
.text {
  color: #000;
  font-family: Helvetica;
  font-size: 18px;
  font-style: normal;
  font-weight: 400;
  line-height: normal;
}
.desc {
  color: #000;
  font-family: Helvetica;
  font-size: 18px;
  font-style: normal;
  font-weight: 400;
  line-height: 30px; /* 152.174% */
}
.button {
  border-radius: 15px;
  background: #4699ff;
  color: #fff;
  text-align: center;
  font-family: Helvetica;
  font-size: 30px;
  font-style: normal;
  font-weight: 700;
  line-height: normal;
  padding: 20px 105px;
  margin-top: 30px;
  display: block;
}
.gender-container {
  display: flex;
  justify-content: space-between;
}

.gender-button {
  border-radius: 10px;
}

.active {
  border-color: #4699ff;
  color: #4699ff;
}

.succ {
  margin: 0;
  text-align: center;
}
.succ-desc {
  color: #666;
  font-family: Helvetica;
  font-size: 20px;
  font-style: normal;
  font-weight: 700;
  line-height: normal;
  margin: 20px 0;
}

@media (max-width: 800px) {
  .container{
    overflow: hidden;
  }
  header {
  }
  main {
    width: 90vw;
    padding: 20px 30px;
  }
  .title {
  font-size: 25px;
  font-weight: 700;
}
.hundred {
  font-size: 30px;
  font-weight: 700;
}

  .contact{
  position: static;
}

  .button{
    padding: 20px;
  }
}

@media (max-width: 1200px) and (min-width: 801px) {
  .contact{
  position: static;
}
}

</style>
